<template>

    <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="单据编码">
            <el-input v-model="formInline.documentNumber" placeholder="单据编码" clearable />
        </el-form-item>
        <el-form-item label="客户名称">
            <el-input v-model="formInline.customerProfileName" placeholder="客户名称" clearable />
        </el-form-item>
        <el-form-item label="销售员">
            <el-input v-model="formInline.salesStaff" placeholder="销售员" clearable />

        </el-form-item>
        <el-form-item label="物料名称">
            <el-input v-model="formInline.materialName" placeholder="物料名称" clearable />
        </el-form-item>
        <el-form-item label="销售类型">
            <el-select v-model="formInline.salesType" placeholder="请选择" clearable style="width: 150px;">
                <el-option :lable="'国内品牌'" value="国内品牌"></el-option>
                <el-option :lable="'外购成品'" value="外购成品"></el-option>
                <el-option :lable="'外购原料'" value="外购原料"></el-option>
                <el-option :lable="'自接订单'" value="自接订单"></el-option>
                <el-option :lable="'自制销售'" value="自制销售"></el-option>
                <el-option :lable="'客供销售'" value="客供销售"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="GetSuppliers()">搜索</el-button>
        </el-form-item>


    </el-form>
    <el-button type="primary" :icon="List" @click="GetSuppliers1()">查询所有</el-button>
    <el-button type="primary" :icon="List" @click="router.push('/SalesOrderdanjuShow')">单据</el-button>
    <el-button type="primary" :icon="Plus" plain @click="router.push('/SalesOrderAddView')">新增</el-button>
    <el-button type="primary" :icon="Download">导入</el-button>
    <el-button type="primary" :icon="Upload">导出</el-button>


    <el-empty description="暂无数据" v-show="suppliers.length == 0" />
    <el-table :data="suppliers" stripe style="width: 100%" v-show="suppliers.length != 0">
        <el-table-column prop="salesOrderId" label="序号" />
        <el-table-column prop="documentNumber" label="单据编码">
            <template #default="scope">
                <el-link type="primary" @click="chakan(scope.row.documentNumber)">{{
                    scope.row.documentNumber }}</el-link>
            </template>
        </el-table-column>
        <el-table-column prop="documentStatus" label="单据状态" />
        <el-table-column prop="customerProfileName" label="客户名称" />
        <el-table-column prop="salesStaff" label="销售员" />
        <el-table-column prop="itemBianma" label="物料编码" />
        <el-table-column prop="itemName" label="物料名称" />
        <el-table-column prop="quantity" label="数量" />
        <el-table-column prop="unitPrice" label="单价" />
        <el-table-column prop="amount" label="金额" />
        <el-table-column prop="numberofpackages" label="发货数量" />
        <el-table-column prop="salesType" label="销售类型">
            <template #default="scope">

                <el-tag type="primary" v-show="scope.row.salesType == '国内品牌'">国内品牌</el-tag>
                <el-tag type="info" v-show="scope.row.salesType == '外购成品'">外购成品</el-tag>
                <el-tag type="success" v-show="scope.row.salesType == '外购原料'">外购原料</el-tag>
                <el-tag type="info" v-show="scope.row.salesType == '自接订单'">自接订单</el-tag>
                <el-tag type="warning" v-show="scope.row.salesType == '自制销售'">自制销售</el-tag>
                <el-tag type="info" v-show="scope.row.salesType == '客供销售'">客供销售</el-tag>
            </template>
        </el-table-column>
        <el-table-column prop="documentDate" label="单据日期">
            <template #default="scope">
                {{ scope.row.documentDate == null ? "" : scope.row.documentDate.substring(0, 10) }}
            </template>
        </el-table-column>

    </el-table>

    <div>
        <tr>
            <td>
                <el-pagination v-model:current-page="formInline.pageIndex" v-model:page-size="formInline.pageSize"
                    :page-sizes="[10, 20, 30, 40, 50]" :background="true" layout="total, slot, prev, pager, next"
                    :total="formInline.totalCount" @size-change="handleSizeChange"
                    @current-change="handleCurrentChange">
                </el-pagination>
            </td>
            <td>
                <el-pagination v-model:current-page="formInline.pageIndex" v-model:page-size="formInline.pageSize"
                    :page-sizes="[10, 20, 30, 40, 50]" :background="true" layout="slot, sizes, jumper"
                    :total="formInline.totalCount" @size-change="handleSizeChange"
                    @current-change="handleCurrentChange">
                </el-pagination>
            </td>
        </tr>
    </div>
</template>

<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useRoute } from 'vue-router'
import axios from 'axios';
import { Plus, Download, Upload, List } from '@element-plus/icons-vue'
import type { TabsPaneContext } from 'element-plus'
const cpiurls = import.meta.env.VITE_APP_API_URL_SalesManagementCommon;//5227
const router = useRouter()
const route = useRoute()

onMounted(() => {
    GetSuppliers()
});

const formInline = reactive({
    documentNumber: '',
    customerProfileName: '',
    salesStaff: '',
    materialName: '',
    salesType: '',
    pageIndex: 1,
    pageSize: 10,
    pageCount: 0,
    totalCount: 0,

})


const handleClick = (tab: TabsPaneContext, event: Event) => {
    console.log(tab, event)
}
//销售订单单据列表
const suppliers: any = ref([]);
const GetSuppliers = () => {
    axios
        .get(
            cpiurls + '/api/SalesOrder/SearchSalesOrderDetail',
            {
                params: {
                    documentNumber: formInline.documentNumber,
                    materialName: formInline.materialName,
                    salesStaff: formInline.salesStaff,
                    customerProfileName: formInline.customerProfileName,
                    salesType: formInline.salesType,
                    pageIndex: formInline.pageIndex,
                    pageSize: formInline.pageSize,
                }
            }
        )
        .then((res) => {
            console.log(res.data.data);
            suppliers.value = res.data.data.list;
            formInline.pageCount = res.data.data.pageCount;
            formInline.totalCount = res.data.data.totalCount;
        })
        .catch((err) => {
            console.log(err);
        });
};

const chakan = (documentNumber: any) => {
    router.push({
        path: '/SalesOrderIntail',
        query: {
            documentNumber: documentNumber
        }
    })
}

const GetSuppliers1 = () => {
    axios
        .get(
            cpiurls + '/api/SalesOrder/SearchSalesOrderDetail',
            {
                params: {
                    documentNumber: '',
                    itemName: '',
                    salesStaff: '',
                    customerProfileName: '',
                    salesType: '',
                    pageIndex: 1,
                    pageSize: 10,
                }
            }
        )
        .then((res) => {
            console.log(res.data.data);
            suppliers.value = res.data.data;
            formInline.pageCount = res.data.pageCount;
            formInline.totalCount = res.data.totalCount;
        })
        .catch((err) => {
            console.log(err);
        });
};

//分页
const handleSizeChange = (val: number) => {
    formInline.pageSize = val
    GetSuppliers()
}
const handleCurrentChange = (val: number) => {
    formInline.pageIndex = val
    GetSuppliers()
}



const formLabelWidth = '140px'

</script>

<style>
.demo-tabs>.el-tabs__content {
    padding: 32px;
    color: #6b778c;
    font-size: 32px;
    font-weight: 600;
}
</style>